package cn.px.rest.controller.sqarepartmanage;

import cn.px.dao.entity.store.SpareStore;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * 导入出入库单据
 *
 */
public class SpareStoreTest {
    private static String PATH = "G:\\depository\\sb\\spring-boot-sb-base\\platform-rest\\src\\test\\java\\com\\test\\";
    private static String file = PATH + "39-2库存.txt";

    public static void main(String[] args) {
        getList();
    }

    public static Map<String,List> getList() {

        /* 读取数据 */
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(file)),
                    "UTF-8"));
            String lineTxt = null;
            List<String> banks = new ArrayList<String>();
            while ((lineTxt = br.readLine()) != null) {
                if(!banks.contains(lineTxt)){
                    banks.add(lineTxt);
                }
            }
            br.close();
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date now = new Date();
            List<SpareStore> inList = new ArrayList<SpareStore>();

            int i = 0;
            for(String bank:banks){
                String[] line = bank.split("\t");
                SpareStore info = new SpareStore();
                //System.out.println(line[0]);
                info.setSpareId(line[0]);
                info.setStoreId(line[1]);
                info.setRemark(line[2] + ";" + line[3]);
                info.setNum(new BigDecimal(line[4]));
                info.setInitNum(new BigDecimal(line[4]));
                info.setPrice(new BigDecimal(line[5]));
                info.setInitPurchasePrice(new BigDecimal(line[5]));
                info.setInitPrice(new BigDecimal(line[5]));
                if(line.length>6){
                    String[] date = line[6].split("/");
                    LocalDateTime localDateTime = LocalDateTime.of(Integer.valueOf(date[0]),
                            Integer.valueOf(date[1]),
                            Integer.valueOf(date[2]),
                            0,
                            0,
                            0);
                    info.setCreatedTime(localDateTime);
                }
                inList.add(info);
            }
            //System.out.println(inList.size());
            Map<String,List> map = new HashMap<String,List>();
            map.put("in", inList);
            return map;
        } catch (Exception e) {
            System.err.println("read errors :" + e);
        }
        return null;
    }

    public static String getStoreId(String name){
        if(name.equals("48岛")){
            return "7";
        }
        if(name.equals("48岛油车")){
            return "1";
        }
        if(name.equals("39/2C号岛")){
            return "8";
        }
        if(name.equals("39/2C号岛油车")){
            return "2";
        }
        if(name.equals("40/2号岛")){
            return "9";
        }
        if(name.equals("41/1号岛")){
            return "10";
        }
        if(name.equals("41/1号岛油车")){
            return "3";
        }
        if(name.equals("47/2号岛")){
            return "11";
        }
        if(name.equals("中心库房")){
            return "12";
        }
        if(name.equals("43/2C号岛")){
            return "13";
        }
        if(name.equals("43/2C号岛油车")){
            return "4";
        }
        return null;
    }
}
